package com.woniuxy.signing.app.util;/**
 * @auther 黄磊
 * @2022/8/8 11:06
 **/

import cn.hutool.json.JSONUtil;
import com.nimbusds.jose.JWSObject;
import com.woniuxy.commons.util.UserDto;
import com.woniuxy.commons.util.WebUtil;

import java.text.ParseException;

/**
 * @author : [天下第一剑]
 * @version : [v1.0]
 * @createTime : [2022/8/8 11:06]
 */
public class TokenToUserDtoUtil {
    public static UserDto getLoginUser() {
        JWSObject jwsObject = null;
        try {
            jwsObject = JWSObject.parse(WebUtil.getRequest().getHeader("accessToken"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String userStr = jwsObject.getPayload().toString();
        UserDto userDto = JSONUtil.toBean(userStr, UserDto.class);
        return userDto;
    }
}
